<template>
  <div>
    <el-form ref="form" :rules="rules" :model="form" label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="部门编号" prop="System_2_20">
            <el-input v-model="form.System_2_20" v-nulltext></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="部门名称" prop="System_2_30">
            <el-input v-model="form.System_2_30" v-nulltext></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="部门负责人" prop="System_2_110">
            <el-input v-model="form.System_2_110" v-nulltext></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="上级部门" prop="System_2_70">
            <mei-select-tree
              :disabled="treedisabled"
              v-model="form.System_2_70"
              width="100%"
              :data="sys2Data"
              idKey="System_2_10"
              pIdKey="System_2_70"
              nameKey="System_2_30"
            ></mei-select-tree>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row style="text-align:right">
        <el-button @click="onSave" type="primary">保存</el-button>
        <el-button @click="close">取消</el-button>
      </el-row>
    </el-form>
  </div>
</template>

<script>
import { System1, System2 } from "@/api";
export default {
  data() {
    const check70 = (rule, value, callback) => {
      if (value == this.form.System_2_10) {
        return callback(new Error("上级部门无效"));
      } else {
        callback();
      }
    };
    return {
      form: {},
      rules: {
        System_2_20: [
          {
            type: "string",
            required: true,
            message: "请输入部门编号",
            trigger: "blur"
          }
        ],
        System_2_30: [
          {
            type: "string",
            required: true,
            message: "请输入部门名称",
            trigger: "blur"
          }
        ],
        System_2_70: [{ validator: check70, trigger: "change" }]
      },
      sys2Data: [],
      treedisabled: true
    };
  },
  //外部属性
  props: {},
  //内部方法
  methods: {
    async initPage() {
      this.sys2Data = await System2.get();
      this.treedisabled = false;
    },
    //关闭
    close() {
      this.thisDialog.close();
    },
    onSave() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          console.log("通过");
          let res = await System2.Save(this.form);
          res.strMS && this.$message(res.strMS);
          this.thisDialog.$emit("onSys2Save", res, this.form);
        } else {
          console.log("没通过");
          return false;
        }
      });
      //res.MsRbool && this.close();
    }
  },
  //组件
  components: {},
  //初始化 异步加async await
  mounted() {
    this.initPage();
  },
  //计算属性
  computed: {},
  //监视
  watch: {}
};
</script>

<style></style>
